﻿// *----------------------------------------------------------------
// Copyright (C) 2017 通通优品
// 版权所有。
// 
// 类名：MallWebCoreModule.cs
// 功能描述：TongTongMall.MallWeb.Core
// 
// Create User：jym 2017/02/09
// 
// Edit User：UserName,EditTime
// Describe：Describe
// ----------------------------------------------------------------*/
using Castle.Facilities.TypedFactory;
using Castle.MicroKernel.Registration;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using TongTongMall.Common;
using TongTongMall.Dependecy;
using TongTongMall.Dependecy.Factory;
using TongTongMall.MallWeb.Core.Configuration;
using TongTongMall.MallWeb.Core.Instance;


using TongTongMall.Modules;

namespace TongTongMall.MallWeb.Core
{
    [DependsOn(
   typeof(KernelModule),
   typeof(CommonModule))]
    public class MallWebCoreModule : BaseModule
    {
        public override void Initialize()
        {
            //注册购物车动态程序集
            InitializeShoppingCartHandle();
            //核销码动态程序集
            InitializeVerifyHandle();
            //注册mapper程序集
            InitializeMapperHandle();
            IocManager.RegisterAssemblyByConvention(Assembly.GetExecutingAssembly());
        }


        public override void PreInitialize()
        {
            //通通mall系统全局配置信息设置
            Configuration.Settings.Providers.Add<MallWebSettingForApplicationProvider>();
            //通通mall商城租户配置信息设置
            Configuration.Settings.Providers.Add<MallWebSettingForTenantProvider>();
            //通通mall 支付系统配置

        }

        private void InitializeMapperHandle()
        {
            //注册Mapper程序集
            //AutoMapper.Mapper.CreateMap<PickAdsDto, UserReceiptAddressDto>()
            //    .ForMember(dto => dto.ID, options => options.MapFrom(x => x.UserPickAdsDetail.UserPcikAdsID))
            //    .ForMember(dto => dto.UserID, options => options.MapFrom(x => x.UserPickAdsDetail.UserID))
            //    .ForMember(dto => dto.IDCardNum, options => options.MapFrom(x => x.UserPickAdsDetail.IDCardNum))
            //    .ForMember(dto => dto.IDCardNum, options => options.MapFrom(x => x.UserPickAdsDetail.IDCardNum))
            //    .ForMember(dto => dto.IDCardNum, options => options.MapFrom(x => x.UserPickAdsDetail.IDCardNum))
            //    .ForMember(dto => dto.IDCardNum, options => options.MapFrom(x => x.UserPickAdsDetail.IDCardNum))
            //    .AfterMap((s, d) =>
            //    {
            //        //d.CartID = Guid.NewGuid();
            //        d.AddDate = Clock.Now;
            //    });
        }

        private void InitializeShoppingCartHandle()
        {
            //根据商品信息注入工厂
            IocManager.IocContainer.AddFacility<TypedFactoryFacility>();

        }


        private void InitializeVerifyHandle()
        {
            //根据商品信息注入工厂
            //IocManager.IocContainer.Register(

             //   );
        }
    }
}
